package com.util.vmsg.beans;

import java.util.ArrayList;
import java.util.List;

import com.google.appengine.api.datastore.Entity;

public class Vehicle {
	private String vehicleNumber;
	private List<MobileNumber> vMsgSubscribers;
	
	public Entity getVehicleEntity()
	{
		Entity vehicleEntity = new Entity("Vehicle",vehicleNumber);
		
		vehicleEntity.setProperty("vehicleNumber",vehicleNumber);
		
		int i=0;
		for(MobileNumber mobileNumber : vMsgSubscribers)
		{
			i++;
			vehicleEntity.setProperty("vMsgSubscriber["+i+"]", mobileNumber.getMobileNumber());
		}
		vehicleEntity.setProperty("vMsgSubscriberListSize",i);
		
		return vehicleEntity;
	}
	
	public static Vehicle getVehicleVO(Entity vehicleEntity)
	{
		Vehicle vehicle = new Vehicle();
		
		String vehicleNumber = vehicleEntity.getProperty("vehicleNumber").toString();
		vehicle.setVehicleNumber(vehicleNumber);
		
		int vMsgSubscriberListSize = ((Long) vehicleEntity.getProperty("vMsgSubscriberListSize")).intValue();
		
		List<MobileNumber> vMsgSubscribers = new ArrayList<MobileNumber>();
		for(int i=1; i<=vMsgSubscriberListSize; i++)
		{
			MobileNumber mobileNumber = new MobileNumber(vehicleEntity.getProperty("vMsgSubscriber["+i+"]").toString(),false,null);
			vMsgSubscribers.add(mobileNumber);
		}
		
		vehicle.setvMsgSubscribers(vMsgSubscribers);
		return vehicle;
	}

	
	public String getVehicleNumber() {
		return vehicleNumber;
	}
	public void setVehicleNumber(String vehicleNumber) {
		this.vehicleNumber = vehicleNumber;
	}
	public List<MobileNumber> getvMsgSubscribers() {
		return vMsgSubscribers;
	}
	public void setvMsgSubscribers(List<MobileNumber> vMsgSubscribers) {
		this.vMsgSubscribers = vMsgSubscribers;
	}
	
	public Vehicle()
	{
		
	}
	
	public Vehicle(String vehicleNumber)
	{
		this.vehicleNumber = vehicleNumber;
	}
	
	public Vehicle(String vehicleNumber, List<MobileNumber> vMsgSubscribers)
	{
		this.vehicleNumber = vehicleNumber;
		this.vMsgSubscribers = vMsgSubscribers;
	}
}
